% Reshaping UK data output from Stata for Matlab input
clear all
load ../data/DataforMatlab/UK_Budget_married0.csv
UK_Budget = UK_Budget_married0;
%%
I = 17; 
NL = 10000;
T = 2017- 1974 + 1;

B_vec_L = NaN(I,NL,T);
w_vec_L = NaN(1,NL,T);
hhw_vec_L = NaN(1,NL,T);
for t = 1:T 
ind = find(UK_Budget(:,1) == 1973+t);

btmp=  UK_Budget(min(ind):max(ind),4:end)';
wtmp =  UK_Budget(min(ind):max(ind),3)';   
hhwtmp =  UK_Budget(min(ind):max(ind),2)';  

[wtmp2, wLind] = sort(wtmp);
btmp2 = btmp(:,wLind,:);
hhwtmp2 = hhwtmp(:,wLind,:);
w_vec_L(1,1:size(ind,1),t) = wtmp2;
w_vec_L(1,size(ind,1):end,t) = NaN;
B_vec_L(:,1:size(ind,1),t) = btmp2;
hhw_vec_L(1,1:size(ind,1),t) = hhwtmp2;
end
 
w_vec_long = reshape(log(w_vec_L),[10000,T]);

I_vec = w_vec_L;
B_vec = B_vec_L;

clearvars -except I_vec B_vec w_vec_long hhw_vec_L
save ../data/DataforMatlab/UK_Budget_married

% %%
% clear
% load ../data/DataforMatlab/price.csv
% pvec_tmp = price./price(1,:);
% save ../data/DataforMatlab/pvec_tmp

